﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Reflection;
using HslCommunication.Serial;

namespace HslCommunication.ModBus
{
	/// <summary>
	/// Modbus-Rtu通讯协议的类库，多项式码0xA001，支持标准的功能码，也支持扩展的功能码实现，地址采用富文本的形式，详细见备注说明<br />
	/// Modbus-Rtu communication protocol class library, polynomial code 0xA001, supports standard function codes, 
	/// and also supports extended function code implementation. The address is in rich text. For details, see the remark
	/// </summary>
	/// <remarks>
	/// 本客户端支持的标准的modbus协议，Modbus-Tcp及Modbus-Udp内置的消息号会进行自增，地址支持富文本格式，具体参考示例代码。<br />
	/// 读取线圈，输入线圈，寄存器，输入寄存器的方法中的读取长度对商业授权用户不限制，内部自动切割读取，结果合并。
	/// </remarks>
	/// <example>
	/// <inheritdoc cref="T:HslCommunication.ModBus.ModbusTcpNet" path="example" />
	/// </example>
	// Token: 0x020000CF RID: 207
	public class ModbusRtu : SerialDeviceBase
	{
		/// <summary>
		/// 实例化一个Modbus-Rtu协议的客户端对象<br />
		/// Instantiate a client object of the Modbus-Rtu protocol
		/// </summary>
		// Token: 0x06000F79 RID: 3961 RVA: 0x0005A9C8 File Offset: 0x00058BC8
		public ModbusRtu()
		{
			base.ByteTransform = new ReverseWordTransform();
		}

		/// <summary>
		/// 指定客户端自己的站号来初始化<br />
		/// Specify the client's own station number to initialize
		/// </summary>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000F7A RID: 3962 RVA: 0x0005A9EC File Offset: 0x00058BEC
		public ModbusRtu(byte station = 1)
		{
			this.station = station;
			base.ByteTransform = new ReverseWordTransform();
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.AddressStartWithZero" />
		// Token: 0x17000243 RID: 579
		// (get) Token: 0x06000F7B RID: 3963 RVA: 0x0005AA18 File Offset: 0x00058C18
		// (set) Token: 0x06000F7C RID: 3964 RVA: 0x0005AA30 File Offset: 0x00058C30
		public bool AddressStartWithZero
		{
			get
			{
				return this.isAddressStartWithZero;
			}
			set
			{
				this.isAddressStartWithZero = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.Station" />
		// Token: 0x17000244 RID: 580
		// (get) Token: 0x06000F7D RID: 3965 RVA: 0x0005AA3C File Offset: 0x00058C3C
		// (set) Token: 0x06000F7E RID: 3966 RVA: 0x0005AA54 File Offset: 0x00058C54
		public byte Station
		{
			get
			{
				return this.station;
			}
			set
			{
				this.station = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.DataFormat" />
		// Token: 0x17000245 RID: 581
		// (get) Token: 0x06000F7F RID: 3967 RVA: 0x0005AA60 File Offset: 0x00058C60
		// (set) Token: 0x06000F80 RID: 3968 RVA: 0x0005AA7D File Offset: 0x00058C7D
		public DataFormat DataFormat
		{
			get
			{
				return base.ByteTransform.DataFormat;
			}
			set
			{
				base.ByteTransform.DataFormat = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.IsStringReverse" />
		// Token: 0x17000246 RID: 582
		// (get) Token: 0x06000F81 RID: 3969 RVA: 0x0005AA90 File Offset: 0x00058C90
		// (set) Token: 0x06000F82 RID: 3970 RVA: 0x0005AAAD File Offset: 0x00058CAD
		public bool IsStringReverse
		{
			get
			{
				return base.ByteTransform.IsStringReverseByteWord;
			}
			set
			{
				base.ByteTransform.IsStringReverseByteWord = value;
			}
		}

		/// <summary>
		/// 检查当前的Modbus-Rtu响应是否是正确的<br />
		/// Check if the current Modbus-Rtu response is correct
		/// </summary>
		/// <param name="send">发送的数据信息</param>
		/// <returns>带是否成功的结果数据</returns>
		// Token: 0x06000F83 RID: 3971 RVA: 0x0005AAC0 File Offset: 0x00058CC0
		protected virtual OperateResult<byte[]> CheckModbusTcpResponse(byte[] send)
		{
			send = ModbusInfo.PackCommandToRtu(send);
			OperateResult<byte[]> operateResult = base.ReadBase(send);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				bool flag2 = operateResult.Content.Length < 5;
				if (flag2)
				{
					result = new OperateResult<byte[]>(StringResources.Language.ReceiveDataLengthTooShort + "5");
				}
				else
				{
					bool flag3 = !SoftCRC16.CheckCRC16(operateResult.Content);
					if (flag3)
					{
						result = new OperateResult<byte[]>(StringResources.Language.ModbusCRCCheckFailed + SoftBasic.ByteToHexString(operateResult.Content, ' '));
					}
					else
					{
						bool flag4 = send[1] + 128 == operateResult.Content[1];
						if (flag4)
						{
							result = new OperateResult<byte[]>((int)operateResult.Content[2], ModbusInfo.GetDescriptionByErrorCode(operateResult.Content[2]));
						}
						else
						{
							bool flag5 = send[1] != operateResult.Content[1];
							if (flag5)
							{
								result = new OperateResult<byte[]>((int)operateResult.Content[1], "Receive Command Check Failed: ");
							}
							else
							{
								result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeRtuCommandToCore(operateResult.Content));
							}
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoil(System.String)" />
		// Token: 0x06000F84 RID: 3972 RVA: 0x0003ABD2 File Offset: 0x00038DD2
		public OperateResult<bool> ReadCoil(string address)
		{
			return this.ReadBool(address);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoil(System.String,System.UInt16)" />
		// Token: 0x06000F85 RID: 3973 RVA: 0x0003ABDB File Offset: 0x00038DDB
		public OperateResult<bool[]> ReadCoil(string address, ushort length)
		{
			return this.ReadBool(address, length);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscrete(System.String)" />
		// Token: 0x06000F86 RID: 3974 RVA: 0x0005ABCD File Offset: 0x00058DCD
		public OperateResult<bool> ReadDiscrete(string address)
		{
			return ByteTransformHelper.GetResultFromArray<bool>(this.ReadDiscrete(address, 1));
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscrete(System.String,System.UInt16)" />
		// Token: 0x06000F87 RID: 3975 RVA: 0x0005ABDC File Offset: 0x00058DDC
		public OperateResult<bool[]> ReadDiscrete(string address, ushort length)
		{
			return this.ReadBoolHelper(address, length, 2);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Read(System.String,System.UInt16)" />
		// Token: 0x06000F88 RID: 3976 RVA: 0x0005ABE8 File Offset: 0x00058DE8
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<byte[][]> operateResult = ModbusInfo.BuildReadModbusCommand(address, length, this.Station, this.AddressStartWithZero, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				List<byte> list = new List<byte>();
				for (int i = 0; i < operateResult.Content.Length; i++)
				{
					OperateResult<byte[]> operateResult2 = this.CheckModbusTcpResponse(operateResult.Content[i]);
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					list.AddRange(operateResult2.Content);
				}
				result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Byte[])" />
		// Token: 0x06000F89 RID: 3977 RVA: 0x0005AC90 File Offset: 0x00058E90
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.CheckModbusTcpResponse(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Int16)" />
		// Token: 0x06000F8A RID: 3978 RVA: 0x0005ACD8 File Offset: 0x00058ED8
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.CheckModbusTcpResponse(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.UInt16)" />
		// Token: 0x06000F8B RID: 3979 RVA: 0x0005AD1C File Offset: 0x00058F1C
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.CheckModbusTcpResponse(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteMask(System.String,System.UInt16,System.UInt16)" />
		// Token: 0x06000F8C RID: 3980 RVA: 0x0005AD60 File Offset: 0x00058F60
		[HslMqttApi("WriteMask", "")]
		public OperateResult WriteMask(string address, ushort andMask, ushort orMask)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteMaskModbusCommand(address, andMask, orMask, this.Station, this.AddressStartWithZero, 22);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.CheckModbusTcpResponse(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.Write(System.String,System.Int16)" />
		// Token: 0x06000F8D RID: 3981 RVA: 0x0005ADA6 File Offset: 0x00058FA6
		public OperateResult WriteOneRegister(string address, short value)
		{
			return this.Write(address, value);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.Write(System.String,System.UInt16)" />
		// Token: 0x06000F8E RID: 3982 RVA: 0x0005ADB0 File Offset: 0x00058FB0
		public OperateResult WriteOneRegister(string address, ushort value)
		{
			return this.Write(address, value);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.Write(System.String,System.Int16)" />/param&gt;
		// Token: 0x06000F8F RID: 3983 RVA: 0x0005ADBC File Offset: 0x00058FBC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, short value)
		{
			ModbusRtu.<WriteAsync>d__28 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__28();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__28>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.Write(System.String,System.UInt16)" />/param&gt;
		// Token: 0x06000F90 RID: 3984 RVA: 0x0005AE10 File Offset: 0x00059010
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ushort value)
		{
			ModbusRtu.<WriteAsync>d__29 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__29();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__29>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.ReadCoil(System.String)" />
		// Token: 0x06000F91 RID: 3985 RVA: 0x0005AE64 File Offset: 0x00059064
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadCoilAsync(string address)
		{
			ModbusRtu.<ReadCoilAsync>d__30 <ReadCoilAsync>d__ = new ModbusRtu.<ReadCoilAsync>d__30();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<ModbusRtu.<ReadCoilAsync>d__30>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.ReadCoil(System.String,System.UInt16)" />
		// Token: 0x06000F92 RID: 3986 RVA: 0x0005AEB0 File Offset: 0x000590B0
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadCoilAsync(string address, ushort length)
		{
			ModbusRtu.<ReadCoilAsync>d__31 <ReadCoilAsync>d__ = new ModbusRtu.<ReadCoilAsync>d__31();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.length = length;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<ModbusRtu.<ReadCoilAsync>d__31>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.ReadDiscrete(System.String)" />
		// Token: 0x06000F93 RID: 3987 RVA: 0x0005AF04 File Offset: 0x00059104
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadDiscreteAsync(string address)
		{
			ModbusRtu.<ReadDiscreteAsync>d__32 <ReadDiscreteAsync>d__ = new ModbusRtu.<ReadDiscreteAsync>d__32();
			<ReadDiscreteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadDiscreteAsync>d__.<>4__this = this;
			<ReadDiscreteAsync>d__.address = address;
			<ReadDiscreteAsync>d__.<>1__state = -1;
			<ReadDiscreteAsync>d__.<>t__builder.Start<ModbusRtu.<ReadDiscreteAsync>d__32>(ref <ReadDiscreteAsync>d__);
			return <ReadDiscreteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.ReadDiscrete(System.String,System.UInt16)" />
		// Token: 0x06000F94 RID: 3988 RVA: 0x0005AF50 File Offset: 0x00059150
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadDiscreteAsync(string address, ushort length)
		{
			ModbusRtu.<ReadDiscreteAsync>d__33 <ReadDiscreteAsync>d__ = new ModbusRtu.<ReadDiscreteAsync>d__33();
			<ReadDiscreteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadDiscreteAsync>d__.<>4__this = this;
			<ReadDiscreteAsync>d__.address = address;
			<ReadDiscreteAsync>d__.length = length;
			<ReadDiscreteAsync>d__.<>1__state = -1;
			<ReadDiscreteAsync>d__.<>t__builder.Start<ModbusRtu.<ReadDiscreteAsync>d__33>(ref <ReadDiscreteAsync>d__);
			return <ReadDiscreteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.WriteOneRegister(System.String,System.Int16)" />
		// Token: 0x06000F95 RID: 3989 RVA: 0x0005AFA4 File Offset: 0x000591A4
		[DebuggerStepThrough]
		public Task<OperateResult> WriteOneRegisterAsync(string address, short value)
		{
			ModbusRtu.<WriteOneRegisterAsync>d__34 <WriteOneRegisterAsync>d__ = new ModbusRtu.<WriteOneRegisterAsync>d__34();
			<WriteOneRegisterAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteOneRegisterAsync>d__.<>4__this = this;
			<WriteOneRegisterAsync>d__.address = address;
			<WriteOneRegisterAsync>d__.value = value;
			<WriteOneRegisterAsync>d__.<>1__state = -1;
			<WriteOneRegisterAsync>d__.<>t__builder.Start<ModbusRtu.<WriteOneRegisterAsync>d__34>(ref <WriteOneRegisterAsync>d__);
			return <WriteOneRegisterAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.WriteOneRegister(System.String,System.UInt16)" />
		// Token: 0x06000F96 RID: 3990 RVA: 0x0005AFF8 File Offset: 0x000591F8
		[DebuggerStepThrough]
		public Task<OperateResult> WriteOneRegisterAsync(string address, ushort value)
		{
			ModbusRtu.<WriteOneRegisterAsync>d__35 <WriteOneRegisterAsync>d__ = new ModbusRtu.<WriteOneRegisterAsync>d__35();
			<WriteOneRegisterAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteOneRegisterAsync>d__.<>4__this = this;
			<WriteOneRegisterAsync>d__.address = address;
			<WriteOneRegisterAsync>d__.value = value;
			<WriteOneRegisterAsync>d__.<>1__state = -1;
			<WriteOneRegisterAsync>d__.<>t__builder.Start<ModbusRtu.<WriteOneRegisterAsync>d__35>(ref <WriteOneRegisterAsync>d__);
			return <WriteOneRegisterAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.WriteMask(System.String,System.UInt16,System.UInt16)" />
		// Token: 0x06000F97 RID: 3991 RVA: 0x0005B04C File Offset: 0x0005924C
		[DebuggerStepThrough]
		public Task<OperateResult> WriteMaskAsync(string address, ushort andMask, ushort orMask)
		{
			ModbusRtu.<WriteMaskAsync>d__36 <WriteMaskAsync>d__ = new ModbusRtu.<WriteMaskAsync>d__36();
			<WriteMaskAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteMaskAsync>d__.<>4__this = this;
			<WriteMaskAsync>d__.address = address;
			<WriteMaskAsync>d__.andMask = andMask;
			<WriteMaskAsync>d__.orMask = orMask;
			<WriteMaskAsync>d__.<>1__state = -1;
			<WriteMaskAsync>d__.<>t__builder.Start<ModbusRtu.<WriteMaskAsync>d__36>(ref <WriteMaskAsync>d__);
			return <WriteMaskAsync>d__.<>t__builder.Task;
		}

		// Token: 0x06000F98 RID: 3992 RVA: 0x0005B0A8 File Offset: 0x000592A8
		private OperateResult<bool[]> ReadBoolHelper(string address, ushort length, byte function)
		{
			OperateResult<byte[][]> operateResult = ModbusInfo.BuildReadModbusCommand(address, length, this.Station, this.AddressStartWithZero, function);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				List<bool> list = new List<bool>();
				for (int i = 0; i < operateResult.Content.Length; i++)
				{
					OperateResult<byte[]> operateResult2 = this.CheckModbusTcpResponse(operateResult.Content[i]);
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<bool[]>(operateResult2);
					}
					int length2 = (int)operateResult.Content[i][4] * 256 + (int)operateResult.Content[i][5];
					list.AddRange(SoftBasic.ByteToBoolArray(operateResult2.Content, length2));
				}
				result = OperateResult.CreateSuccessResult<bool[]>(list.ToArray());
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000F99 RID: 3993 RVA: 0x0005B177 File Offset: 0x00059377
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			return this.ReadBoolHelper(address, length, 1);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Boolean[])" />
		// Token: 0x06000F9A RID: 3994 RVA: 0x0005B184 File Offset: 0x00059384
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteBoolModbusCommand(address, values, this.Station, this.AddressStartWithZero, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.CheckModbusTcpResponse(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Boolean)" />
		// Token: 0x06000F9B RID: 3995 RVA: 0x0005B1CC File Offset: 0x000593CC
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteBoolModbusCommand(address, value, this.Station, this.AddressStartWithZero, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.CheckModbusTcpResponse(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusRtu.Write(System.String,System.Boolean)" />
		// Token: 0x06000F9C RID: 3996 RVA: 0x0005B210 File Offset: 0x00059410
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			ModbusRtu.<WriteAsync>d__41 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__41();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__41>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt32(System.String,System.UInt16)" />
		// Token: 0x06000F9D RID: 3997 RVA: 0x0005B264 File Offset: 0x00059464
		[HslMqttApi("ReadInt32Array", "")]
		public override OperateResult<int[]> ReadInt32(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<int[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransInt32(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt32(System.String,System.UInt16)" />
		// Token: 0x06000F9E RID: 3998 RVA: 0x0005B2C0 File Offset: 0x000594C0
		[HslMqttApi("ReadUInt32Array", "")]
		public override OperateResult<uint[]> ReadUInt32(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<uint[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransUInt32(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadFloat(System.String,System.UInt16)" />
		// Token: 0x06000F9F RID: 3999 RVA: 0x0005B31C File Offset: 0x0005951C
		[HslMqttApi("ReadFloatArray", "")]
		public override OperateResult<float[]> ReadFloat(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<float[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransSingle(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt64(System.String,System.UInt16)" />
		// Token: 0x06000FA0 RID: 4000 RVA: 0x0005B378 File Offset: 0x00059578
		[HslMqttApi("ReadInt64Array", "")]
		public override OperateResult<long[]> ReadInt64(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<long[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransInt64(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt64(System.String,System.UInt16)" />
		// Token: 0x06000FA1 RID: 4001 RVA: 0x0005B3D4 File Offset: 0x000595D4
		[HslMqttApi("ReadUInt64Array", "")]
		public override OperateResult<ulong[]> ReadUInt64(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<ulong[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransUInt64(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadDouble(System.String,System.UInt16)" />
		// Token: 0x06000FA2 RID: 4002 RVA: 0x0005B430 File Offset: 0x00059630
		[HslMqttApi("ReadDoubleArray", "")]
		public override OperateResult<double[]> ReadDouble(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<double[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransDouble(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Int32[])" />
		// Token: 0x06000FA3 RID: 4003 RVA: 0x0005B48C File Offset: 0x0005968C
		[HslMqttApi("WriteInt32Array", "")]
		public override OperateResult Write(string address, int[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.UInt32[])" />
		// Token: 0x06000FA4 RID: 4004 RVA: 0x0005B4BC File Offset: 0x000596BC
		[HslMqttApi("WriteUInt32Array", "")]
		public override OperateResult Write(string address, uint[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Single[])" />
		// Token: 0x06000FA5 RID: 4005 RVA: 0x0005B4EC File Offset: 0x000596EC
		[HslMqttApi("WriteFloatArray", "")]
		public override OperateResult Write(string address, float[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Int64[])" />
		// Token: 0x06000FA6 RID: 4006 RVA: 0x0005B51C File Offset: 0x0005971C
		[HslMqttApi("WriteInt64Array", "")]
		public override OperateResult Write(string address, long[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.UInt64[])" />
		// Token: 0x06000FA7 RID: 4007 RVA: 0x0005B54C File Offset: 0x0005974C
		[HslMqttApi("WriteUInt64Array", "")]
		public override OperateResult Write(string address, ulong[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Double[])" />
		// Token: 0x06000FA8 RID: 4008 RVA: 0x0005B57C File Offset: 0x0005977C
		[HslMqttApi("WriteDoubleArray", "")]
		public override OperateResult Write(string address, double[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt32Async(System.String,System.UInt16)" />
		// Token: 0x06000FA9 RID: 4009 RVA: 0x0005B5AC File Offset: 0x000597AC
		[DebuggerStepThrough]
		public override Task<OperateResult<int[]>> ReadInt32Async(string address, ushort length)
		{
			ModbusRtu.<ReadInt32Async>d__54 <ReadInt32Async>d__ = new ModbusRtu.<ReadInt32Async>d__54();
			<ReadInt32Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<int[]>>.Create();
			<ReadInt32Async>d__.<>4__this = this;
			<ReadInt32Async>d__.address = address;
			<ReadInt32Async>d__.length = length;
			<ReadInt32Async>d__.<>1__state = -1;
			<ReadInt32Async>d__.<>t__builder.Start<ModbusRtu.<ReadInt32Async>d__54>(ref <ReadInt32Async>d__);
			return <ReadInt32Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt32Async(System.String,System.UInt16)" />
		// Token: 0x06000FAA RID: 4010 RVA: 0x0005B600 File Offset: 0x00059800
		[DebuggerStepThrough]
		public override Task<OperateResult<uint[]>> ReadUInt32Async(string address, ushort length)
		{
			ModbusRtu.<ReadUInt32Async>d__55 <ReadUInt32Async>d__ = new ModbusRtu.<ReadUInt32Async>d__55();
			<ReadUInt32Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<uint[]>>.Create();
			<ReadUInt32Async>d__.<>4__this = this;
			<ReadUInt32Async>d__.address = address;
			<ReadUInt32Async>d__.length = length;
			<ReadUInt32Async>d__.<>1__state = -1;
			<ReadUInt32Async>d__.<>t__builder.Start<ModbusRtu.<ReadUInt32Async>d__55>(ref <ReadUInt32Async>d__);
			return <ReadUInt32Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadFloatAsync(System.String,System.UInt16)" />
		// Token: 0x06000FAB RID: 4011 RVA: 0x0005B654 File Offset: 0x00059854
		[DebuggerStepThrough]
		public override Task<OperateResult<float[]>> ReadFloatAsync(string address, ushort length)
		{
			ModbusRtu.<ReadFloatAsync>d__56 <ReadFloatAsync>d__ = new ModbusRtu.<ReadFloatAsync>d__56();
			<ReadFloatAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<float[]>>.Create();
			<ReadFloatAsync>d__.<>4__this = this;
			<ReadFloatAsync>d__.address = address;
			<ReadFloatAsync>d__.length = length;
			<ReadFloatAsync>d__.<>1__state = -1;
			<ReadFloatAsync>d__.<>t__builder.Start<ModbusRtu.<ReadFloatAsync>d__56>(ref <ReadFloatAsync>d__);
			return <ReadFloatAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt64Async(System.String,System.UInt16)" />
		// Token: 0x06000FAC RID: 4012 RVA: 0x0005B6A8 File Offset: 0x000598A8
		[DebuggerStepThrough]
		public override Task<OperateResult<long[]>> ReadInt64Async(string address, ushort length)
		{
			ModbusRtu.<ReadInt64Async>d__57 <ReadInt64Async>d__ = new ModbusRtu.<ReadInt64Async>d__57();
			<ReadInt64Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<long[]>>.Create();
			<ReadInt64Async>d__.<>4__this = this;
			<ReadInt64Async>d__.address = address;
			<ReadInt64Async>d__.length = length;
			<ReadInt64Async>d__.<>1__state = -1;
			<ReadInt64Async>d__.<>t__builder.Start<ModbusRtu.<ReadInt64Async>d__57>(ref <ReadInt64Async>d__);
			return <ReadInt64Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt64Async(System.String,System.UInt16)" />
		// Token: 0x06000FAD RID: 4013 RVA: 0x0005B6FC File Offset: 0x000598FC
		[DebuggerStepThrough]
		public override Task<OperateResult<ulong[]>> ReadUInt64Async(string address, ushort length)
		{
			ModbusRtu.<ReadUInt64Async>d__58 <ReadUInt64Async>d__ = new ModbusRtu.<ReadUInt64Async>d__58();
			<ReadUInt64Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<ulong[]>>.Create();
			<ReadUInt64Async>d__.<>4__this = this;
			<ReadUInt64Async>d__.address = address;
			<ReadUInt64Async>d__.length = length;
			<ReadUInt64Async>d__.<>1__state = -1;
			<ReadUInt64Async>d__.<>t__builder.Start<ModbusRtu.<ReadUInt64Async>d__58>(ref <ReadUInt64Async>d__);
			return <ReadUInt64Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadDoubleAsync(System.String,System.UInt16)" />
		// Token: 0x06000FAE RID: 4014 RVA: 0x0005B750 File Offset: 0x00059950
		[DebuggerStepThrough]
		public override Task<OperateResult<double[]>> ReadDoubleAsync(string address, ushort length)
		{
			ModbusRtu.<ReadDoubleAsync>d__59 <ReadDoubleAsync>d__ = new ModbusRtu.<ReadDoubleAsync>d__59();
			<ReadDoubleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<double[]>>.Create();
			<ReadDoubleAsync>d__.<>4__this = this;
			<ReadDoubleAsync>d__.address = address;
			<ReadDoubleAsync>d__.length = length;
			<ReadDoubleAsync>d__.<>1__state = -1;
			<ReadDoubleAsync>d__.<>t__builder.Start<ModbusRtu.<ReadDoubleAsync>d__59>(ref <ReadDoubleAsync>d__);
			return <ReadDoubleAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Int32[])" />
		// Token: 0x06000FAF RID: 4015 RVA: 0x0005B7A4 File Offset: 0x000599A4
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, int[] values)
		{
			ModbusRtu.<WriteAsync>d__60 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__60();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__60>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.UInt32[])" />
		// Token: 0x06000FB0 RID: 4016 RVA: 0x0005B7F8 File Offset: 0x000599F8
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, uint[] values)
		{
			ModbusRtu.<WriteAsync>d__61 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__61();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__61>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Single[])" />
		// Token: 0x06000FB1 RID: 4017 RVA: 0x0005B84C File Offset: 0x00059A4C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, float[] values)
		{
			ModbusRtu.<WriteAsync>d__62 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__62();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__62>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Int64[])" />
		// Token: 0x06000FB2 RID: 4018 RVA: 0x0005B8A0 File Offset: 0x00059AA0
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, long[] values)
		{
			ModbusRtu.<WriteAsync>d__63 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__63();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__63>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.UInt64[])" />
		// Token: 0x06000FB3 RID: 4019 RVA: 0x0005B8F4 File Offset: 0x00059AF4
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ulong[] values)
		{
			ModbusRtu.<WriteAsync>d__64 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__64();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__64>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Double[])" />
		// Token: 0x06000FB4 RID: 4020 RVA: 0x0005B948 File Offset: 0x00059B48
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, double[] values)
		{
			ModbusRtu.<WriteAsync>d__65 <WriteAsync>d__ = new ModbusRtu.<WriteAsync>d__65();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusRtu.<WriteAsync>d__65>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000FB5 RID: 4021 RVA: 0x0005B99A File Offset: 0x00059B9A
		public override string ToString()
		{
			return string.Format("ModbusRtu[{0}:{1}]", base.PortName, base.BaudRate);
		}

		// Token: 0x04000436 RID: 1078
		private byte station = 1;

		// Token: 0x04000437 RID: 1079
		private bool isAddressStartWithZero = true;
	}
}
